class UpdateUsers < ActiveRecord::Migration
    def self.up
          
        # add column to keep user logged in
        add_column :users, :remember_token_expires_at, :datetime
        add_column :users, :remember_token, :string, :limit => 40

        # add fields for user verification        
        add_column :users, :activation_code, :string, :limit => 40
        add_column :users, :activated_at, :datetime
        
        # use sql to update all current users so they were activated when they signed up
        execute 'UPDATE users SET activated_at = created_at WHERE verified=1 AND deleted=0'
        
        remove_column :users, :login_token
        remove_column :users, :verified
               
        add_column "users", "password_reset_code", :string, :limit => 40 
    end
    
    def self.down
    
        remove_column :users, :activation_code
        remove_column :users, :activated_at
        
        remove_column :users, :remember_token_expires_at
        remove_column :users, :remember_token
        
        add_column :users, :login_token, :string, :limit => 40
        add_column :users, :verified, :integer, :default => 0
        
        remove_column "users", "password_reset_code" 
    end
end
